#include "IniFile.h"
#include <stdio.h>
#include <assert.h>

IniFile::IniFile()
{
	memset(m_ptcFileName, 0, sizeof(m_ptcFileName));
	memset(m_ptcAppName, 0, sizeof(m_ptcAppName));
}

IniFile::~IniFile()
{
}

void IniFile::Init(TCHAR *ptcFileName)
{
	_tcscpy_s(m_ptcFileName, MAX_PATH, ptcFileName);
}

void IniFile::SetAppName(TCHAR *ptcAppName)
{
	_tcscpy_s(m_ptcAppName, MAX_PATH, ptcAppName);
}

bool IniFile::WriteString(const TCHAR *ptcKeyName, const TCHAR *value)
{
	assert( m_ptcAppName[0] != NULL && m_ptcFileName[0] != NULL );

	BOOL ret = WritePrivateProfileString(m_ptcAppName, ptcKeyName, value, m_ptcFileName);
	return ret == TRUE;
}

bool IniFile::WriteStruct(const TCHAR *ptcKeyName, void *pvValue, UINT size)
{
	assert( m_ptcAppName[0] != NULL && m_ptcFileName[0] != NULL );

	BOOL ret = WritePrivateProfileStruct(m_ptcAppName, ptcKeyName, pvValue, size, m_ptcFileName);
	return ret == TRUE;
}

bool IniFile::WriteAll(const TCHAR *ptcValue, UINT size)
{
	return true;
}


UINT32 IniFile::ReadString(const TCHAR *ptcKeyName, const TCHAR *ptcDefault, TCHAR *value, UINT size)
{
	assert( m_ptcAppName[0] != NULL && m_ptcFileName[0] != NULL );

	DWORD ret = GetPrivateProfileString(m_ptcAppName, ptcKeyName, ptcDefault, value, size, m_ptcFileName);

	return ret;
}

UINT32 IniFile::ReadStruct(const TCHAR *ptcKeyName, void *pvValue, UINT size)
{
	assert( m_ptcAppName[0] != NULL && m_ptcFileName[0] != NULL );

	UINT ret = GetPrivateProfileStruct(m_ptcAppName, ptcKeyName, pvValue, size, m_ptcFileName);

	return ret;
}

UINT32 IniFile::ReadInt(const TCHAR *ptcKeyName, int nDefault)
{
	assert( m_ptcAppName[0] != NULL && m_ptcFileName[0] != NULL );

	UINT ret = GetPrivateProfileInt(m_ptcAppName, ptcKeyName, nDefault, m_ptcFileName);

	return ret;
}

UINT32 IniFile::ReadAll(TCHAR *value, UINT size)
{
	assert( m_ptcAppName[0] != NULL && m_ptcFileName[0] != NULL );

	DWORD ret = GetPrivateProfileSection(m_ptcAppName, value, size, m_ptcFileName);

	return ret;
}

UINT32 IniFile::ReadSectionList(TCHAR *value, UINT size)
{
	assert( m_ptcAppName[0] != NULL && m_ptcFileName[0] != NULL );

	DWORD ret = GetPrivateProfileSectionNames(value, size, m_ptcFileName);

	return ret;
}